import UIKit
import Toast_Swift

public class CommonToast: NSObject {
    
    static let shared = CommonToast()
    
    private let toastView: UIView? = {
        let toastView = UIApplication.shared.keyWindow
        return toastView
    }()
    
    func showToast(_ message: String, duration: TimeInterval? = CGFloat.app_hubInterval) {
        if toastView != nil {
            var style = ToastStyle()
            style.titleAlignment = .center
            style.messageAlignment = .center
            toastView!.makeToast(message, duration: duration!, position: .center, style: style)
        }
    }
    
    func hideToast() {
        if toastView != nil {
            toastView?.isUserInteractionEnabled = true
            toastView!.hideAllToasts()
        }
    }
    
    func showIndicator() {
        if toastView != nil {
            toastView?.isUserInteractionEnabled = false
            toastView!.makeToastActivity(.center)
        }
    }
    
    func hideIndicator() {
        if toastView != nil {
            toastView?.isUserInteractionEnabled = true
            toastView!.hideToastActivity()
        }
    }
}
